# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=radicale
pkgver=3.1.8
pkgrel=2
pkgdesc="Free and open-source CalDAV and CardDAV server"
url="https://radicale.org/3.0.html"
arch="noarch"
license="GPL-3.0-or-later"
depends="python3 py3-passlib py3-vobject py3-defusedxml py3-dateutil py3-setuptools"
checkdepends="py3-pytest py3-pytest-flake8 py3-pytest-isort py3-pytest-cov py3-waitress"
pkgusers="radicale"
pkggroups="radicale"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/Kozea/radicale/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	py311-test_server.patch
	"
subpackages="$pkgname-openrc $pkgname-pyc"
builddir="$srcdir/Radicale-$pkgver"

build() {
	python3 setup.py build
}

check() {
	# install the package to test_install directory for testing
	python3 setup.py install --root="$PWD"/test_install

	PYTHONPATH="$(echo $PWD/test_install/usr/lib/python3*/site-packages)" \
		pytest -c /dev/null
}

package() {
	python3 setup.py install --skip-build --prefix=/usr --root="$pkgdir"

	install -d -o radicale -g radicale "$pkgdir"/var/lib/radicale \
		"$pkgdir"/var/log/radicale

	install -d "$pkgdir"/etc/radicale
	install -m640 -g radicale config "$pkgdir"/etc/radicale/
	install -m640 -g radicale rights "$pkgdir"/etc/radicale/

	install -Dm755 "$srcdir"/radicale.initd "$pkgdir"/etc/init.d/radicale
	install -Dm644 "$srcdir"/radicale.confd "$pkgdir"/etc/conf.d/radicale
}

sha512sums="
5c4b55ee9cfc5060a0e0cf1f284d2c5a354bcabd7a088214e917fabb0083bcd172fd92aeb59b1f869f34e04f8c276efbed15c2a3ff2fdbc81b2220586bbaf31b  radicale-3.1.8.tar.gz
f1eb4477ca7d7d8040837b712289f18d6b62c7f862a8e9bea32968a49b8bf4394360b5440c815aa23df48ba0aaac61bcb8c9d6e7575c3b23da2ac05a45eac194  radicale.initd
09bb6228ba07039b97b317d4547a33b7ebf9c8f47ff72b870fc2f5e46de620e0614d993c5c96d73f0ad6196d469bb0f7206478781abf314af1d598e3132d678e  radicale.confd
7b0d2d78f01b379e9c7ac1e2e509986f72ce6de1749cd358502c01bf1346e25348885c172315fc3052fa6131950086bb90857958b1c1df78cb7048999a18193d  py311-test_server.patch
"
